<?php
/**
 * <https://y.st./>
 * Copyright © 2018 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'<{title}>' => 'Tool-based drops in <code>minestats</code>',
	'takedown' => '2017-11-01',
	'<{body}>' => <<<END
<img src="/img/CC_BY-SA_4.0/y.st./weblog/2018/08/09.jpg" alt="A duck that walked up close to me" class="framed-centred-image" width="649" height="480"/>
<section id="drudgery">
	<h2>Drudgery</h2>
	<p>
		My discussion post for the day:
	</p>
	<blockquote>
		<p>
			The story begins with a sick woman in bed attended by a priest and a medical doctor.
			She tells them she needs them to leave, because &quot;he&quot; can&apos;t know they&apos;re there.
			The priest was just talking about Yahweh, so he assumes that&apos;s who she&apos;s referring to, and says Yahweh sees and knows all.
			Of course, the reader doesn&apos;t know who &quot;he&quot; is, but it&apos;s pretty obvious it&apos;s not Yahweh she&apos;s referring to.
			The others won&apos;t leave, and the woman starts to panic.
			They ask what she needs, and she repeats that she needs them gone.
			Se says she has no time for this, and pulls out a gun, threatening them and forcing them to get out.
			With the sense of urgency displayed, I thought she was going to turn into a monster.
			Given the title of the piece, Dreamless, I assumed she transformed every night instead of going to sleep.
			They reluctantly leave, closing the door as they were instructed, and a sign swings into view that reads &quot;DO NOT DISTURB BETWEEN 0900 AND 1400&quot;.
			It was an odd time span, lasting through the morning and into the afternoon instead of night, but it seemed to confirm that she was dangerous during this time every day.
			She goes to sleep and (as the narrator) tells you she couldn&apos;t believe what she saw, acting as a cliffhanger.
		</p>
		<p>
			Queue flashback sequence, explaining her backstory.
			As a child, she starts speaking what seems might be gibberish.
			It turns out to be Japanese.
			She&apos;s never been exposed to Japanese though.
			Her mother is worried and her father convinces one of his friend to lie and claim he taught her some Japanese words.
			At this point, I figured the girl must have two lives.
			When she sleeps here in the States, she wakes up in another body in Japan.
			The father also forbids the girl from speaking Japanese around her mother.
		</p>
		<p>
			The girl ends up telling her doll she can&apos;t have tea parties with it any more, and ends up going on a couple tangents before moving on to an explanation of what really happens when she sleeps.
			She wakes up in the body of a boy in Japan.
			However, he isn&apos;t her.
			They&apos;re entirely separate people, but when either one sleeps, they experience the life of the other.
			They&apos;re unable to control the other person&apos;s body, and instead, but act out whatever the other person is doing.
			It&apos;s him that she would be referring to years later, not wanting him to see her sick.
			The two have become friends, talking to each other by talking to themselves.
			Of course, the other person can&apos;t respond until the two switch to the other body though, causing the girl to think of the situation as being similar to having a pen pal.
			The mother overhears, and is never seen alive again.
			The two friends attend the mother&apos;s funeral in the girl&apos;s body.
		</p>
		<p>
			The girl starts trying to escape her own life as much as possible by living his life instead.
			She sleeps sixteen hours each day to spend his whole waking day in his body with him.
			The oversleeping leads to illness though.
			She learns of a new telephone line to Japan, and stops sleeping so much.
			Instead, she works as hard as she can to save up enough money to place a call to him and speak with him in person.
			Working an entire year, she finally saves up enough to place a three-minute long-distance call.
			The boy doesn&apos;t cooperate though.
			He doesn&apos;t go to the telephone office.
			Instead, he walks to a pond and tells himself (or rather, her) that he knows she&apos;s just trying to prove to herself that he&apos;s real, and she should check her mailbox.
			There, she finds a letter from him, proving he&apos;s not a dream.
			It turns out that this wasn&apos;t why she wanted to call him though, and in fact, it was he that feared <strong>*she*</strong> might not be real.
		</p>
		<p>
			Several scenes are shown of both their lives.
			After a bit, the boy predicts the girl is going to try to come to Japan, but he doesn&apos;t feel it&apos;s safe and wants to stop her.
			The United States and Japan are on the brink of war, and he things that waiting until the war ends will be safer.
		</p>
		<p>
			The father of the girl never asked any questions about why she speaks Japanese, even after his wife and her mother died, and the girl finally snaps.
			She demands that the father say something, so he replies that she speaks Japanese for the same reason he speaks German.
			Assuming he&apos;s right, she&apos;s inherited her strange situation from him.
			But if it&apos;s genetic, this means there must be at least three families with the strange gene, and probably more.
			There&apos;s the United States bloodline, the Japanese bloodline, and the German bloodline.
		</p>
		<p>
			The girl buys the three-minute telephone call and tells the boy she wants him to sleep every day during certain hours and only those hours: the hours she&apos;ll be asleep.
			This will cause them to jump into the other person&apos;s body during times the body is inactive.
			They won&apos;t see each other&apos;s lives, but instead see the blackness of the backs of each other&apos;s eyelids.
			She wants some time apart from him, which explains the strange scene the story began with.
			She needed to get to sleep as they&apos;d arranged for him to be asleep or he&apos;d see her life and her illness.
			At the same time though, sleeping at the same time had for the most part been good for her health.
			Perhaps having her mind stay away for years at a time with no rest had been taking a toll on her; she never liked to sleep at the same time as him because she found the darkness and hearing the sounds in his room to be eerie.
		</p>
		<p>
			Finally, the war starts.
			The boy either chooses to join the war or is drafted.
			It&apos;s never really told.
			In any case, he&apos;s flying a fighter plane that he sabotaged.
			First, he sabotaged the radio and failed to load up much ammunition.
			Next, he flew past the battle without firing, then spent what little ammo he had firing into the ocean.
			And finally, he used the plane to reach the girl, and they finally meet in person.
		</p>
		<p>
			Frustratingly, the story ends on a cliffhanger.
			The two finally meet, but then what?
		</p>
		<div class="APA_references">
			<h3>References:</h3>
			<p>
				Crosby, B. (2009). DREAMLESS. Retrieved from <a href="http://dreamless.keenspot.com/"><code>http://dreamless.keenspot.com/</code></a>
			</p>
		</div>
	</blockquote>
</section>
<section id="Minetest">
	<h2>Minetest</h2>
	<img src="/img/CC_BY-SA_3.0/minetest.net./weblog/2018/08/09.png" alt="A makeshift bridge from my project to the orchard" class="framed-centred-image" width="800" height="600"/>
	<p>
		I came up with the beginnings of a plan as to what to do about sand drops.
		If you recall from yesterday, I need sandstone to drop a single sand node when dug, but it doesn&apos;t have to exhibit this behaviour all the time.
		I decided I&apos;d include a second drop, one that would offset the value loss.
		It&apos;d basically be made of the remaining three sand from the sandstone.
		However, this is a really annoying behaviour.
		When people dig sandstone, they&apos;re not going to want to irreversibly lose three sand from it.
		People like to renovate.
		They&apos;ll want to be able to restructure buildings made from sandstone without gathering a bunch more sand.
		So, I decided to base the behaviour on tool levels.
		Above a certain threshold, either the sand and by-product or the sandstone itself would drop, and below the threshold, the other would drop instead.
		Players simply would need to use the correct tool to get the result they wanted.
	</p>
	<p>
		I remembered that the Mintest $a[API] documentation mentioned tool level in regards to drops, so I took a look.
		As it turns out, tool level is intended to be used in exactly the way I intended to use it, but the game doesn&apos;t actually handle that in any automated way.
		The documentation specifically says that nodes must implement this themselves, which means it must be done in the node callback methods.
		That doesn&apos;t work for my purposes though.
		There&apos;s no way for <code>minestats</code> to detect it if it&apos;s done within a custom callback.
	</p>
	<p>
		I don&apos;t remember why I did it, but I took a look at the source code for the function that figures out node drops.
		As it turns out, there&apos;s an undocumented feature in there.
		Seriously, once I found it, I searched the documentation for it.
		There&apos;s no sign of it there.
		Anyway, the feature allows a drop possibility table to include requirements of the tool&apos;s name for a drop to occur.
		You can either specify an exact tool name or you can specify a substring that the tool&apos;s name must contain.
		For example, I could specify &quot;shovel&quot; to allow all shovels from Minetest Game and most shovels defined in other mods to trigger the drop.
		Likewise, I could specify &quot;mese&quot; to instead cause the drop on all mese tools from Minetest Game and most mese tools from other mods.
	</p>
	<p>
		I decided the best course of action was to use a custom digging callback that would call the default dig handler, then detect what tool was used and put a replacement node in place if certain tools were used to perform the dig.
		That would allow the tool to &quot;break off some of the sand&quot; as the drop I needed, then leave something behind.
		I debated back and forth between making the by-product node some sort of broken sandstone or instead carved sandstone.
		I decided carved sandstone was more likely to be the more popular option, so I decided to go with that.
		I don&apos;t think people would really want broken sandstone, though it might look cool when building ancient ruins.
	</p>
	<p>
		After some tinkering, I managed to use this feature also to prevent drops during leaf decay.
		Players that don&apos;t want to clean up their leaves by hand will need to do more mining and tree farming to get the items needed to remake exotic saplings.
		Players that want to put that effort into fully caring for their chimeric monstrosities will instead be able to get offspring and replant.
		Either way takes effort, it&apos;s just a matter of where you want to put that effort.
	</p>
	<p>
		<code>minestats</code> works as though this feature didn&apos;t exist.
		It simply doesn&apos;t account for it.
		I started work on fixing <code>minestats</code>, but I couldn&apos;t complete it tonight.
		It&apos;s just too complicated.
		On Minetest&apos;s side, all it has to do is compare the tool used to perform the dig against a set of tool names and tool name substrings.
		The actual tool used is already known, so a simple comparison does the trick.
		<code>minestats</code> has to work in reverse though.
		It doesn&apos;t know what tool will be used.
		Furthermore, it doesn&apos;t even have a list of tools that <strong>*might*</strong> be used.
		Testing revealed that any held item is considered the tool for the Minetest&apos;s comparison, even if it lacks tool capabilities.
		Furthermore, the tool used doesn&apos;t even have to be defined.
		That means there are a nearly infinite set of possible tools that could be used; <code>minestats</code> can&apos;t know until it&apos;s too late what undefined item stacks are still lying around from when some other mod was uninstalled.
		That means <code>minestats</code> has nothing solid to compare against.
		Instead, it must build up lists of what could have been dropped given hypothetical tools with unknown names.
		It&apos;s got to build up lists of what those names could be and couldn&apos;t be, making sure not to allow drops that could never be gotten together to be treated as though they could.
		Needless to say, accomplishing that task is turning out to be a nightmare.
		I&apos;ve made progress though.
		And I think I can finish the job.
	</p>
	<p>
		In light of both new developments in <code>minestats</code> and recent plans to add reproduction capability to chimeric plants in the <code>alchemy</code>-related mods, I think I&apos;m going to wait to release the chimeric plants.
		I might release them in sets of 256, using a single palette-based node for the dropping node and another for each of the dropping items.
		This does mean some chimeric plants will never see the light of day (as there won&apos;t be a number of elements that would allow the number of chimeric plants of any given type to be evenly divided), but it&apos;ll save a lot of node definition space.
		Other nodes and items may be later condensible using palettes, but these nodes and drops will have their names cemented by <code>minestats</code> right away.
		I have to get it right the first time, not do it wrong and condense later.
	</p>
</section>
END
);
